package com.common.sdk.net.connect.http.util;

import android.graphics.Bitmap;

import com.common.sdk.net.connect.http.center.tools.HttpLog;

/**
 * Basic LRU Memory cache as L1 Image cache
 */
public class ImageLruCache extends LruCache<String, Bitmap> {
    public ImageLruCache(int maxSize) {
        super(maxSize);
    }

    @Override
    protected int sizeOf(String key, Bitmap bm) {
        return bm.getRowBytes() * bm.getHeight();
    }

    public Bitmap getBitmap(String url) {
        HttpLog.debug("Retrieved item from Mem Cache");
        return get(url);
    }

    public void putBitmap(String url, Bitmap bitmap) {
        HttpLog.debug("Added item to Mem Cache");
        put(url, bitmap);
    }

    public void clearCache() {
        HttpLog.debug("Clear mem cache");
        evictAll();
    }
}
